package com.itheima.io.字符流;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class CharDtreamDemo5 {
    public static void main(String[] args) throws IOException {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张三","李四","王五","赵六","钱七");
        setName(list);



    }

    private static void setName(ArrayList<String> list) throws IOException {
        //创建字符缓冲输出流
        BufferedWriter bw = new BufferedWriter(new FileWriter("day12_IO流_字符流\\name.txt"));

        //遍历集合
       /* for (String name : list) {
            bw.write(name);
            bw.write(System.lineSeparator());
        }*/

        list.forEach((name)->{
            try {
                bw.write(name);
                bw.newLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

        //关闭流
        bw.close();
    }
}
